<?php

namespace App\Http\Controllers;

use App\Model\MachineSlots;
use App\Service\MachineService;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use GuzzleHttp\Client;

class MachineController extends BaseController
{
    public function index(){
        $machineList = MachineService::getMyMachineList();
        return view('machine/index',[
            'machineList'=>$machineList
        ]);
      //  return view('index/index');
    }

    public function editMachineSlots(Request $request){
        $str_machineId = $request->get('id');
        $model_slot = MachineService::getMachineSlots($str_machineId);
        return view('machine/editSlots',[
            'slotList'=>$model_slot,
            'machineId'=>$str_machineId,
        ]);
    }

    public function doEditMachineSlots(Request $request){
        try{
            $int_slotid = $request->input('slot_id');
            $str_machineId = $request->input('mc_id');
            $int_goodsId = $request->input('goods_id');
            $float_goodsCost = $request->input('good_cost');
            $float_salePrice = $request->input('sale_price');

            MachineSlots::where([
                'slot_id' =>$int_slotid,
                'machine_id' =>$str_machineId,
            ])->update([
                'good_id'=>$int_goodsId,
                'good_cost'=>$float_goodsCost,
                'sale_price'=>$float_salePrice,
            ]);
            return ['code'=>0,'msg'=>'ok'];
        }catch (\Exception $exception){
            return ['code'=>1,'msg'=>'error'];
        }


    }
    //生成补货清单
    public function getLacks(Request $request){
        $machineList = MachineService::getMyMachineList();

        if($request->isMethod('post')){
            $arr_machineList = $request->input('machine_list');
        }
        return view('machine/getlack',[
            'machineList'=>$machineList
        ]);
    }

}
